<?php

namespace App\Http\Controllers;

use App\Rules\PhoneRule;
use App\Services\CodeService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;


class CodeController extends Controller
{
    function send(Request $request){
         Validator::make($request->input(),[
             'phone'=>['required',new PhoneRule(),Rule::unique('users')]
         ])->validate();
         $code = app(CodeService::class)->send($request->input('phone'),'SMS_190793806');
         return $this->success('验证码发送成功',['code'=>$code]);
    }
    //重置密码的验证码发送
    function repassword_send(Request $request){
        Validator::make($request->input(),[
            'phone'=>['required',new PhoneRule(),Rule::exists('users')]
        ])->validate();
        $code = app(CodeService::class)->send($request->input('phone'),'SMS_190793806');
        return $this->success('验证码发送成功',['code'=>$code]);
    }
}
